<?php
include_once "header.php";

if(isset($_POST["id"])){
	$daftar_user = new Daftar_user();
	$user=$daftar_user->getAktifUser();
	$kd_sm = $_POST["id"];
}

$cek_field="";

if (ISSET($_POST["tambah_posisi_sm"])){

	if($_POST['posisi_awal']=="" || $_POST['posisi_akhir']==""){
		
		$cek_field = "Peringatan: Silahkan isikan seluruh data yang tersedia.";
	
	} else {
		$daftar_posisi_sm = new Daftar_posisi_surat();
		$posisi_sm = new Posisi_surat();
		$posisi_sm->setKd_surat($_POST["id"]);
		$posisi_sm->setPosisi_awal($_POST["posisi_awal"]);
		$posisi_sm->setPosisi_akhir($_POST["posisi_akhir"]);
		$posisi_sm->setCatatan($_POST["catatan"]);
		$posisi_sm->setWaktu(date("Y-m-d H:i:s"));
		
		$daftar_posisi_sm->addPosisiSM($posisi_sm);
		
		header("Location:detil_sm.php?id=".$_POST["id"]."");
		}
	
}
?>

<div id="container">
	<div id="errorcont">
		<?php echo $cek_field;
		?>
	</div>
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Surat Masuk > Detil > Rekam Posisi
			</div>
			<div id="body">
			</br>
			<form name="form1" method="POST" action="rekam_posisi_sm.php">
			<input type="hidden" name="tambah_posisi_sm">
			<input type="hidden" name="id" value="<?php echo $kd_sm; ?>">
			<table border=0 cellspacing=0 cellpadding=4 width=100%>		
				<tr>
					<td>Posisi Awal</td>
					<td>:</td>
					<td>
					<select name="posisi_awal">
	
					<?php
						foreach($user as $User){
							if($_SESSION['nip']== $User->getNip()){
								echo "<option value=".$User->getNip()." selected>".$User->getNip()." - ".ucwords($User->getNama())."</option>";
							} else{
								echo "<option value=".$User->getNip().">".$User->getNip()." - ".ucwords($User->getNama())."</option>";
							}
						}
					?>
					</select>
					</td>
				</tr>
				<tr>				
					<td>Posisi AKhir</td>
					<td>:</td>
					<td>
					<select name="posisi_akhir">
					<option value=""> Pilih posisi tujuan </option>
					<?php
						foreach($user as $User){
							echo "<option value=".$User->getNip().">".$User->getNip()." - ".ucwords($User->getNama())."</option>";
						}
					?>
					</select>
					</td>
				</tr>
				<tr>	
					<td>Catatan</td>
					<td>:</td>
					<td><textarea name="catatan" cols=70 rows=2 ></textarea></td>
				</tr>
								
			</table>
			<br>
			<input type="submit" value="Simpan"> 
			<input type="button" value="Batal" onClick="window.location.href='detil_sm.php?id=<?php echo $kd_sm; ?>'">
			</form>
						
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">
	$(function() { 
	$("#tgl").datepicker({dateFormat: "yy-mm-dd",
											buttonImage:'../jquery/css/images/calendar.gif',
											buttonImageOnly: true,
											showOn: 'button'
	}); 
	});
</script>

